package collection;
public class genericMethod {

    public static void main(String[] args) {
        GT1<String> i1 = new GT1<>("nn");
        System.out.println(i1.getName().getClass().getName());
        i1.sayHello(12);
        i1.bc(true,12,"Stirng");
//        i1.bs("a","b");


    }

}

class GT1<T>{
    private T name;

    public T getName() {
        return name;
    }

    public void setName(T name) {
        this.name = name;
    }

    public GT1(T name) {
        this.name = name;
    }

    //如果方法的泛型也是T，则覆盖类型中的T
    public <E> T sayHello(E param){
        System.out.println(param.getClass().getName());//java.lang.Integer

        return name;
    }

    //可变参数
    //运行的时候,参数为：true,12,"str"类型推导为：Serializable[]。参数为"a","b",推导为String[]

    public <E> void bc(E... param){
        System.out.println(param.getClass().isArray());//true
//        System.out.println(param);
        for (E e :
                param) {

            System.out.println(e.getClass().getSimpleName()+":"+e);

        }
    }
    public void bs(String... param){


        System.out.println(param);
        System.out.println(param.getClass().isArray());//true

//        System.out.println(param.getClass().getName());
    }

}
